<extend name="Extends/base" />
<block name="title">提现管理</block>
<block name="css">
</block>
<block name="body_style">class="bgc-f2f4f6"</block>
<block name="body">
    <div class="pt30 plr20">
        <div class="form-layout form-inline">
            <form id='myForm'>
                <em class="pop-close"></em>

                <div class="control-group">
                    <label class="control-label"><sub class="control-sub"></sub> 提现状态：</label>
                    <div class="control-form">
                        <div class="cus-sel cus-sel-h33" data-toggle="formSelect">
                            <div class="cus-sel-chosed">
                                <input type="text" name="state" value="1" style="display:none;">
                                <span class="cus-sel-chosed-txt" data-value="">提现中</span>
                                <span class="jselect-icon"></span>
                            </div>
                            <div class="cus-sel-list" style="display: none;">
                                <ul>
                                    <li class="empty-sel"><a href="javascript:;" data-value="">-请选择-</a></li>
                                    <li><a href="javascript:;" data-value="1">提现中</a></li>
                                    <li><a href="javascript:;" data-value="2">已提现</a></li>
                                    <li><a href="javascript:;" data-value="3">提现失败</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>

            </form>

            <div class="control-group">
                <a href="javascript:;" class="c-btn c-btn-blue mr10 search-btn">查询</a>
            </div>
        </div>

        <div class="c-nodata pt100 c-t-center">
            <img src="__PC__/images/nodata.png">
            <p class="pt30 c-f14 msg"></p>
        </div>

        <div id="myList" class="c-hide">
        </div>
    </div>
</block>
<block name="js">
    <script type="text/javascript" src="__CST__/js/api.withdrawal.js?v={:C('JS_CSS_VERSION')}"></script>
    <script type="text/javascript">
        var currPage = 1;
        $(function () {
            getWithdrawalList(currPage);
        });

        //点击搜索
        $(document).on('click', '.search-btn', function () {
            getWithdrawalList(currPage = 1);
        });

        //点击分页
        $(document).on('click', '.my-page li a', function () {
            var page = $(this).attr('data-page');
            if (!page) {
                return false;
            }

            var total = $('.my-page').attr('data-total');
            if (parseInt(page) > parseInt(total)) {
                page = total;
            }
            getWithdrawalList(currPage = page);
        });

        /**
         * 获取提现列表
         **/
        function getWithdrawalList(page, callback) {
            if (typeof callback != "function") {
                callback = emptyFunc;
            }
            var data = getSeachData();
            page = page ? page : 1;
            data.page = page;
            doGetWithdrawalList(data, function (res) {
                if (res.Code != 10000) {
                    showErr(res.Message);
                    $('#myList').hide();
                    callback(res);
                    return false;
                }

                $('#myList').show().html(res.Result.html);
                hideErr();
                callback(res);
            })
        }

        /**
         * 获取搜索的数据
         * @returns {{}}
         */
        function getSeachData() {
            var fromData = $('#myForm').serializeArray();
            var data = {};
            $.each(fromData, function () {
                var name = this.name;
                var value = $.trim(this.value);
                if (value) {
                    data[name] = value;
                }
            });
            return data;
        }

        //提现
        $(document).on('click', '.pass-btn', function () {
            var id = $(this).attr('data-id');
            if (!id) {
                $.toast("提现申请异常");
                return false;
            }
            $.alert("是否确认该记录提现", {
                "ok": function () {
                    doPassWithdrawal(id, function (res) {
                        if (res.Code != 10000) {
                            $.toast(res.Message);
                            return false;
                        }
                        $.toast("提现处理中成功", 2000, function () {
                            getWithdrawalList(currPage);
                        })
                    });
                }
            })
        });

        //驳回提现申请
        $(document).on("click", '.cancel-btn', function () {
            var id = $(this).attr('data-id');
            if (!id) {
                $.toast("提现申请异常");
                return false;
            }

            var html = "<div><span>驳回原因:</span>" +
                "<textarea id='cancelMsg' class='textarea textarea-w220' placeholder='请输入驳回原因'></textarea>" +
                "</div>";
                
            $.alert(html, {
                "ok": function () {
                    var msg = $('#cancelMsg').val();
                    if(!msg){
                        $.toast("请输入驳回原因");
                    }
                    doCancelWithdrawal(id, msg, function (res) {
                        if (res.Code != 10000) {
                            $.toast(res.Message);
                            return false;
                        }
                        $.toast("驳回成功", 2000, function () {
                            getWithdrawalList(currPage);
                        })
                    });
                }
            })
        });

        /**
         * 显示页面错误页面
         * @param msg
         */
        function showErr(msg) {
            $('.c-nodata').show().find('.msg').html(msg);
        }

        /**
         * 隐藏错误页面
         */
        function hideErr() {
            $('.c-nodata').hide().find('.msg').text('');
        }
    </script>
</block>